package com.ajaaxx.service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ajaaxx.datatypes.Question;
import com.ajaaxx.datatypes.Subject;
import com.ajaaxx.datatypes.User;
import com.ajaaxx.repo.EvaluationRepository;
import com.ajaaxx.service.EvaluationService;
import com.ajaaxx.util.Util;


@Service("evaluationService")
public class EvaluationServiceImpl implements EvaluationService{
	
	@Autowired
	private EvaluationRepository evaluationRepository;
	
	public User getUserBasedOnCedulla(int cedulla){
		return evaluationRepository.getUserBasedOnCedulla(cedulla);
	}

	public Set<Question> getQuestions(int cedulla, int subjectId,String semester,String userType) {
		Set<Question> questions = new HashSet<Question>();
		Set<Question> fetchedQuestions = evaluationRepository.getQuestions();
		for(Question question : fetchedQuestions){
			if((question.getSubjectId()==subjectId) & Util.mapUserType(question.getUserType()).equals(userType)) questions.add(question);
		}
		
		return questions;
	}

	public Set<Subject> getSubjects(User user) {
		return evaluationRepository.getSubjects(user);
	}

	public boolean submitSurveyResult(User user, List<Question> questions) {
		return evaluationRepository.submitSurveyResult(user, questions);
	}

}
